﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Drawing;
using ITAP.ShprossesBuilder.Modelling;
using System.Windows.Forms;
using ITAP.Core.Modelling;

namespace ITAP.ShprossesBuilder.Manipulation
{
    public class CommandEditorZoomOut : IModelControlCommand
    {
        private MouseManagerEvent mouseEvent;

        public MouseManagerEvent MouseEvent
        {
            get { return mouseEvent; }
            set { mouseEvent = value; }
        }

        private bool executeImmediately = false;

        public bool ExecuteImmediately
        {
            get { return executeImmediately; }
            set { executeImmediately = value; }
        }
        private string name;

        public string Name
        {
            get { return name; }
        }

        private Point mouseDownPoint;
        private ModelControl modelControl;
        #region IModelControlCommand Members

        public ModelControl ModelControl
        {
            get
            {
                return modelControl;
            }
            set
            {
                modelControl = value;
            }
        }

        public System.Drawing.Point MouseDownPoint
        {
            get
            {
                return mouseDownPoint;
            }
            set
            {
                mouseDownPoint = value;
            }
        }

        public System.Drawing.Point MouseUpPoint
        {
            get
            {
                return mouseDownPoint;
            }
            set
            {
                mouseDownPoint = value;
            }
        }

        public System.Drawing.Point MouseMovePoint
        {
            get
            {
                return mouseDownPoint;
            }
            set
            {
                mouseDownPoint = value;
            }
        }

        #endregion

        public CommandEditorZoomOut(ModelControl modelControl, string name, bool executeImmediately)
        {

            this.executeImmediately = executeImmediately;
            this.name = name;
            this.modelControl = modelControl;
        }

        #region ICommand Members

        public void StartExecute()
        {
            if (modelControl.ModelContainer.InnerComponents.Count == 0)
                return;

            modelControl.UseAutoScale = false;
            RectangleF bbox = modelControl.ModelContainer.BoundingBox;
            ModelPoint centerPoint = modelControl.CoordinateConverter.ScreenPointToModelPoint(mouseDownPoint, modelControl.ClientRectangle.Size.Width, modelControl.ClientRectangle.Size.Height, bbox, modelControl.Camera);
            modelControl.ZoomOut(centerPoint, 0.9);
        }

        public void Execute()
        {
            //throw new NotImplementedException();
        }

        public void EndExecute()
        {
            //throw new NotImplementedException();
        }

        public bool CanUndo
        {
            get { throw new NotImplementedException(); }
        }

        public bool Undo(ModelControl modelControl)
        {
            throw new NotImplementedException();
        }

        public bool Redo(ModelControl modelControl)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            CommandEditorZoomOut clone = new CommandEditorZoomOut(modelControl, name, executeImmediately);
            clone.MouseEvent = this.MouseEvent;
            //clone.ComponentsForProcessing = new List<Shprosses.Modelling.Components.IComponent>(ComponentsForProcessing);
            clone.MouseDownPoint = this.MouseDownPoint;
            clone.MouseMovePoint = this.MouseMovePoint;
            clone.MouseUpPoint = this.MouseUpPoint;
            return clone;
        }

        #endregion

        #region ICommand Members


        public bool IsNeedModelUpdate
        {
            get { return false; }
        }

        #endregion

        #region ICommand Members


        private bool enabled = true;
        public bool Enabled
        {
            get
            {
                return enabled;
            }
            set
            {
                enabled = value;
            }
        }

        #endregion

        #region ICommand Members


        public bool IsNeedVisitorsUpdate
        {
            get { return false; }
        }

        #endregion
    }
}
